/**
 * @author qixiaobo
 */
$(function(){
	$("#google").attr("style", "cursor:pointer");
	$("#google").click(function() {
		window.open("https://www.google.com/ncr");
	});
	$("#search").click(function() {
		if ($("#q").val().trim() === "") {
			alert("请输入查询字符串!");
			return;
		}
		$("#frmsearch").submit();
		return false;
	});
   $('.pagination').jqPagination({
        link_string: '/pages/{page_number}',
        current_page: pageIndex, //设置当前页 默认为1
        max_page: pagesCount, //设置最大页 默认为1
        page_string: '当前第' + pageIndex + '页,共' + pagesCount + '页',
        paged: function(page){
            var href = window.location.href;
            href = href.indexOf("/pages") == -1 ? href : href.substring(0, href.indexOf("/pages"));
            window.location.href = href + "/pages/" + page;
        }
    });
});
/**
 * 修改
 * @param {Object} seqNo
 */
function doEdit(seqNo,element){
    if (seqNo === "0") {
    //主题
	 $("#formPost").attr("action", $("#formPost").attr("baseUrl"));
    }
	else{
		  $("#formPost").attr("action", $("#formPost").attr("baseUrl") + "/" + $(element).attr("entrypt"));
	}
	 window.location.href = $("#formPost").attr("action")+"?type=edit";
}

/**
 * 管理，操作包括move，delete
 * @param {Object} operation
 * @param {Object} seqNo
 */
function doManage(operation, seqNo,element){
	var type="回复";
 	if(seqNo==='0'){
		type="主题";
	}
    if(operation==="delete"){	
	if(confirm("您确定删除该条"+type+"吗?")){
		if(type==="主题"){
			 var href = window.location.href;
            href = href.indexOf("/pages") == -1 ? href : href.substring(0, href.indexOf("/pages"));
			$("#formPost").attr("action",href);
			$("#_method").val("delete");
			$("#formPost").submit();
		}
		else if(type="回复"){
			$("#formPost").attr("action", $("#formPost").attr("baseUrl") + "/" + $(element).attr("entrypt"));
			$("#_method").val("delete");
			$("#formPost").submit();
		}
	}
 }
}
/**
 * 回复
 * @param {Object} seqNo
 */
function doReply(seqNo, nickName,element){


    if (seqNo === "0") {
        //此时为回复主题
        $("#formPost").attr("titleHidden", "Re: 回复 " + "楼主  " + nickName + " 的帖子");
        $("#formPost").attr("action", $("#formPost").attr("baseUrl"));
    }
    else {
        //此时为回复回复
        $("#formPost").attr("titleHidden", "Re: 回复 " + seqNo + "楼" + nickName + " 的帖子");
        $("#formPost").attr("action", $("#formPost").attr("baseUrl") + "/" + $(element).attr("entrypt"));
    }
    window.location.href = $("#formPost").attr("action") + "?titleHidden=" + $("#formPost").attr("titleHidden");
}

/**
 * 举报
 * @param {Object} seqNo
 */
function doReport(seqNo, nickName){

}

/**
 *
 * 引用
 * @param {Object} seqNo
 */
function doQuote(seqNo,nickName,topicid,replyid){
     $("#formPost").attr("action", $("#formPost").attr("baseUrl"));
	var href= $("#formPost").attr("action") + "?seqNo=" +seqNo+"&topicId="+topicid+"&replyId="+replyid;
   window.location.href=href;
}

